package com.villaday.idf.adapter3;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.villaday.idf.R;
import com.villaday.idf.base.AbsRecyclerViewAdapter;
import com.villaday.idf.model3.MemberGuestEntity;

public class ResidentAdapter extends AbsRecyclerViewAdapter<MemberGuestEntity.BodyBean> {

    View.OnClickListener onClickListener;

    public ResidentAdapter(Context context, View.OnClickListener onClickListener) {
        super(context, com.villaday.idf.R.layout.recycle_resident);
        this.onClickListener = onClickListener;
    }


    @Override
    public void onBindHolder(AbsRecyclerViewAdapter.RecyclerViewHolder holder, MemberGuestEntity.BodyBean d, int position) {
        ImageView imageView = (ImageView) holder.getView(R.id.iv_ri);

        if (d.isPreferred()) {
            imageView.setImageResource(R.drawable.public_small_check_selected);
        } else {
            imageView.setImageResource(R.drawable.public_small_check);
        }

        if (d.getGivenNameEn() != null && d.getGivenNameEn().length() > 0 && d.getFamilyNameEn() != null && d.getFamilyNameEn().length() > 0) {
            TextView tv = (TextView) holder.getView(R.id.tv_ri_en);
            tv.setText(d.getFamilyNameEn().toUpperCase() + "/" + d.getGivenNameEn().toUpperCase());
            holder.getView(R.id.tv_ri_en).setVisibility(View.VISIBLE);
        } else {
            holder.getView(R.id.tv_ri_en).setVisibility(View.INVISIBLE);
        }

        ImageView ivDelete = (ImageView) holder.getView(R.id.iv_ri_delete);
        ivDelete.setTag(position);
        ivDelete.setOnClickListener(onClickListener);

        if (d.isDeleted()) {
            ivDelete.setVisibility(View.VISIBLE);
        } else {
            ivDelete.setVisibility(View.GONE);
        }


        holder.bindTextView(R.id.tv_ri, d.getNameCn());
    }
}
